package org.mech.sefer.client.ui.spring.task;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.pivot.util.concurrent.Task;
import org.apache.pivot.util.concurrent.TaskExecutionException;

/**
 * <p>
 * The ReflectionTask is task that invoke method on bean passing arguments. It is all done through reflection
 * </p>
 * <p>
 * Date: 26.4.2012 10:34:29
 * </p>
 *
 * @author martin.krajc
 */
@SuppressWarnings("rawtypes")
public class ReflectionTask extends Task {
	private Object[] args;
	private Method method;
	private Object bean;

	@Override
	public Object execute() throws TaskExecutionException {
		try {
			return method.invoke(bean, args);
		} catch (IllegalArgumentException e) {
			throw new TaskExecutionException(e);
		} catch (IllegalAccessException e) {
			throw new TaskExecutionException(e);
		} catch (InvocationTargetException e) {
			throw new TaskExecutionException(e);
		}
	}

	public Object[] getArgs() {
		return args;
	}

	public void setArgs(Object[] args) {
		this.args = args;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	public Object getBean() {
		return bean;
	}

	public void setBean(Object bean) {
		this.bean = bean;
	}

}
